#include <bits/stdc++.h>
using namespace std;

struct Car {
    int d, v, a;
};

int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    scanf("%d", &t);
    for (int n, m, l, v;t--;) {
        scanf("%d %d %d %d", &n, &m, &l, &v);
        bool A = true, B = true, C = true;
        vector<Car> cars(n + 1);
        int mx = 0, mn = 2e9, mxp = 0, mnd = 0;
        for (int d, v, a, i = 1; i <= n; i++) {
            scanf("%d %d %d", &d, &v, &a);
            if (a) A = false;
            if (a <= 0) B = false;
            if (a >= 0) C = false;
            cars[i] = {d, v, a};
            mn = min(mn, v);
            mnd = min(mnd, d);
        }
        vector<int> p(m + 1);
        for (int i = 1; i <= m; i++) {
            scanf("%d", &p[i]);
            mxp = max(p[i], mxp);
        }
        for (int i = 1; i <= n; i++) {
            if (cars[i].d > mxp) continue;
            mn = min(mn, v);
            mx = max(mx, v);
        }
        if ((A || C) && mx <= v)
            printf("%d\n", m);
        else if ((A || B) && mx > v)
            printf("%d\n", m - 1);
        else if (B && mx <= v) {
            bool b = false;
            for (int i = 1; i <= n; i++) {
                if (cars[i].d >= mxp) continue;
                double nv = sqrt(cars[i].v + 2 * cars[i].a * (mxp - cars[i].d));
                if (nv > v) {
                    printf("%d\n", m - 1);
                    b = true;
                    break;
                }
            }
            if (!b) printf("%d\n", m);
        }
        else {
            vector<int> vis(n + 1);
            for (int i = 1; i <= n; i++) {
                int last = 1;
                for (int j = 1; j <= m; j++) {
                    if (p[j] < cars[i].d) continue;
                    double nv = sqrt(cars[i].v + 2 * cars[i].a * (p[j] - cars[i].d));
                    if (nv > v) {
                        vis[last] = 0;
                        vis[j] = 1;
                        last = j;
                        break;
                    }
                }
            }
            int sum = 0;
            for (int i = 1; i <= n; i++)
                sum += vis[i];
            printf("%d\n", sum);
        }
    }
    return 0;
}













